<?php

/**
 * Created by PhpStorm.
 * User: 志俊
 * Date: 2015/6/4 0004
 * Time: 14:34
 */
class Music_model extends CI_Model
{

    var $Id = '';
    var $title = '';
    var $url = '';

    function __construct()
    {
        parent::__construct();
    }

    function play_music($music_num, $style)
    {
        $max_music = $this->db->select_max("Id")->get("music")->row_array();
        $min_music = $this->db->select_min("Id")->get("music")->row_array();
        switch ($style) {
            case -1:
                if ($min_music['Id'] == $music_num) {
                    $music_num = intval($max_music['Id']) + 1;
                }
                $music = $this->db->where('Id <', $music_num)->order_by('Id desc')->get("music")->row_array();
                break;
            case 0:
                $music = $this->db->where('Id =', $music_num)->limit(1)->get("music")->row_array();
                break;
            case 1:
                if ($max_music['Id'] == $music_num) {
                    $music_num = intval($min_music['Id']) - 1;
                }
                $music = $this->db->where('Id >', $music_num)->order_by('Id asc')->get("music")->row_array();
                break;
        }
        $music['query'] = $this->db->last_query();
        return $music;
    }
}
